package com.zjh.springcloud.controller;

import com.zjh.common.R;
import com.zjh.entity.User;
import com.zjh.springcloud.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: UserClientController
 * Description:
 * @Author zjh
 * @Create 2023/10/10 9:33
 */
@Controller
@RequestMapping("/userClient")
public class UserClientController {
	
	@Autowired
	private UserFeign userFeign;
	
	@GetMapping("/user_manage")
	public String ToMenuManage(){
		return "user_manage";
	}
	
	@GetMapping("/findAll")
	@ResponseBody
	public R<List<User>> findAllUser(@RequestParam("page") Integer begin, @RequestParam("limit") Integer pagesize){
		return userFeign.findAllUser((begin-1)*pagesize, pagesize);
	}
	
	@GetMapping("/deleteById/{id}")
	public String deleteOne(@PathVariable("id") Integer id){
		userFeign.deleteById(id);
		return "redirect:/userClient/user_manage";
	}
	@GetMapping("toSaveUser")
	public String toSaveUser(){
		return "user_add";
	}
	
	@PostMapping("/save")
	public String save(User user){
		userFeign.saveOne(user);
		return "redirect:/menuClient/menu_manage";
	}
	
}
